<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../include/taglib.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>后台管理信息修改</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<%@ include file="../include/jsCss.jsp"%>

  </head>
  
  <body>
    	<form action="user/admin-user!userSaveOrUpdate.html"
			onsubmit="return saveUpdate();" method="post">
			<table border="1">
				<tr>
					<td colspan="2">
						添加会员信息  带 *号为必填项a
					</td>
				</tr>
				<tr>
					<td>
						<span class="spanMsg">*</span>用户名
					</td>
					<td>
						<input type="text" name="userName" id="userName" value="${adminUserDto.userName}" onblur="valUserName();"/>
						<span id="uNameMsg" >请输入您的登录账号,字母或数字开头4-18个字符</span>
						<span id="nameMsg" class="spanMsg"></span>
						<input type="hidden" name="id" value="${adminUserDto.id}"/>
					</td>
				</tr>
				<tr>
					<td>
						<span class="spanMsg">*</span>密码
					</td>
					<td>
						<input type="password" name="userPwd" value="${adminUserDto.userPwd}" onblur="valPassword();"/>
						<span id="uPwdMsg">密码长度为6-16位，区分大小写</span>
						<span id="pwdMsg" class="spanMsg"></span>
					</td>
				</tr>
				
				<tr>
					<td>
						<span class="spanMsg">*</span>性别
					</td>
					<td>
						<s:if test="adminUserDto.userSex==0">
							<input type="radio" name="userSex" value="0" checked="checked" />
								男
							<input type="radio" name="userSex" value="1" />
								女
						</s:if>
						<s:elseif test="adminUserDto.userSex==1">
							<input type="radio" name="userSex" value="0"/>
								男
							<input type="radio" name="userSex" value="1" checked="checked"/>
								女
						</s:elseif>
						
					</td>
				</tr>
				
				<tr>
					<td>
						真实姓名
					</td>
					<td>
						<input type="text" name="realName" value="${adminUserDto.realName}"/>
						<span id="rTrueNameMsg">请输入真实姓名</span>
						
					</td>
				</tr>
				
				<tr>
					<td>
						身份证
					</td>
					<td>
						<input type="text" name="userIdNo" value="${adminUserDto.userIdNo}"/>
						<span id="uIdNoMsg">请输入身份证号码</span>
					</td>
				</tr>
				<!--  <tr>
					<td>
						固定电话
					</td>
					<td>
						<input type="text" name="userMobile" />
						&nbsp;&nbsp;
					</td>
				</tr>-->
				<tr>
					<td>
						<span class="spanMsg">*</span>手机
					</td>
					<td>
						<input type="text" name="userPhone" value="${adminUserDto.userPhone}" onblur="valPhone();"/>
						<span id="uPhoneMsg">请输入11位手机号码</span>
						<span id="phoneMsg" class="spanMsg"></span>
					</td>
				</tr>
				
				<%--  <tr>
					<td>
						邮编
					</td>
					<td>
						<input type="text" name="userZipCode" value="${adminUserDto.userZipCode}"/>
					</td>
				</tr>
				<tr>
					<td>
						QQ
					</td>
					<td>
						<input type="text" name="userqq" value="${adminUserDto.qq}"/>
					</td>
				</tr>--%>
				<tr>
					<td>
						<span class="spanMsg">*</span>邮箱
					</td>
					<td>
						<input type="text" name="userEmail" value="${adminUserDto.userEmail}" onblur="valUserEmail();"/>
						<span id="uEmail">请输入格式正确邮箱</span>
						<span id="email" class="spanMsg"></span>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="submit" value="提交" />
						&nbsp;&nbsp;
						<input type="reset" value="重置" />
					</td>
				</tr>
			</table>
		</form>
  </body>
</html>
<script type="text/javascript">
		function saveUpdate() {
     	    var userName =  $("input[name='userName']").val();//用户
     	    var pwsValue = $("input[name='userPwd']").val();//密码
     	    //var truePwsValue = $("input[name='userPwdTrue']").val(); //确认密码
     	    var phoneValue = $("input[name='userPhone']").val(); //手机号码
			var userEmail = $("input[name='userEmail']").val();//邮箱
			var phoneReg = /^\d{11}$/;
			var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/;
     	    
			//用户名
     		if($.trim(userName) == ''){
     			$("#uNameMsg").hide();
     			$("#nameMsg").text("请输入您的登录账号,字母或数字开头4-18个字符");
     			return false;
     		}else{
     			$("#uNameMsg").show();
     			$("nameMsg").hide();
     		}
     		
     		if($.trim(userName).length<4 || $.trim(userName).length>18){
     			$("#uNameMsg").hide();
     			$("#nameMsg").text("请输入您的登录账号,字母或数字开头4-18个字符");
     			return false;
     		}else{
     			$("#uNameMsg").show();
     			$("#nameMsg").hide();
     		}
     		
     		//验证用户是否存在
   			$.ajax({
   				type : "post",
				url : "user/register!userNameValidate.html",
				data :{
					userName : userName
				},
				success : function(result){ 
					
					if (result == -1) {
						$("#nameMsg").show();
						$("#uNameMsg").hide();
						$("#nameMsg").text("帐户已存在!");
						return false;
					} 
				}
   			});
     		
     		//密码
     		if($.trim(pwsValue)==''){
				$("#uPwdMsg").hide();
     			$("#pwdMsg").text("请输入6位以上的密码!");
     			return false;
			}else{
				$("#uPwdMsg").show();
     			$("pwdMsg").hide();
			}
			
			if($.trim(pwsValue).length<6){
     			$("#uPwdMsg").hide();
     			$("#pwdMsg").text("请输入6位以上的密码!");
     			return false;
     		}else{
     			$("#uPwdMsg").show();
     			$("#pwdMsg").hide();
     		}
			
     		
     		if ($.trim(phoneValue) == '') {
     			$("#uPhoneMsg").hide();
     			$("#phoneMsg").text("请输入手机号码!");
     			return false;
     		}else{
     			$("#uPhoneMsg").show();
     			//$("#phoneMsg").hide();
     		}
     		
     		if ($.trim(phoneValue) != '') {
				if(!phoneReg.test(phoneValue)){
					$("#phoneMsg").show();
					$("#phoneMsg").text("请输入11位手机号码!");
					$("#uPhoneMsg").hide();	
					alert(1111);
					return false;
				}else{
					$("#uPhoneMsg").show();
					$("#phoneMsg").hide();
				}
     		}
     		
     		if($.trim(userEmail) == ''){
     			$("#uEmail").hide();
     			$("#email").text("请输入你的邮件!");
     			return false;
     		}else{
     			$("#uEmail").show();
			    //$("#email").hide();
     		}
     		
     		if($.trim(userEmail) != ''){
	    		if(!reg.test($.trim(userEmail))){
			          $("#uEmail").hide();
			          $("#email").text("请输入正确的邮件格式");
			          return false;
				}else{
					  $("#uEmail").show();
				      $("#email").hide();
				}
    		}
     		
     		
			return true;
     	}
     	
     	//验证用户名是否合格
     	function valUserName(){
     		var userName = $("#userName").val();
     		alert(userName);
     		if($.trim(userName) == ''){
     			$("#uNameMsg").hide();
     			$("#nameMsg").text("请输入您的登录账号,字母或数字开头4-18个字符");
     			return;
     		}else{
     			$("#uNameMsg").show();
     			$("nameMsg").hide();
     		}
     		
     		if($.trim(userName).length<4 || $.trim(userName).length>18){
     			$("#uNameMsg").hide();
     			$("#nameMsg").text("请输入您的登录账号,字母或数字开头4-18个字符");
     			return;
     		}else{
     			$("#uNameMsg").show();
     			$("#nameMsg").hide();
     		}
     		
     		//验证用户是否存在
   			$.ajax({
   				type : "post",
				url : "register!userNameValidate.html",
				data :{
					userName : userName
				},
				success : function(result){ 
					
					if (result == -1) {
						$("#nameMsg").show();
						$("#uNameMsg").hide();
						$("#nameMsg").text("帐户已存在!");//在用
						return;
					} 
				},
				error : function(result) {
					alert("数据读取失败！");
				}
   			});
     	}
     	
     	function valPassword(){
     		//<input type="password" name="userPwd" onblur="valPassword();"/>
			//			<span id="uPwdMsg">密码长度为6-16位，区分大小写</span>
			//			<span id="pwdMsg" class="spanMsg"></span>
			
			var pwsValue = $("input[name='userPwd']").val();
			if($.trim(pwsValue)==''){
				$("#uPwdMsg").hide();
     			$("#pwdMsg").text("请输入6位以上的密码!");
     			return;
			}else{
				$("#uPwdMsg").show();
     			$("pwdMsg").hide();
			}
			
			if($.trim(pwsValue).length<6){
     			$("#uPwdMsg").hide();
     			$("#pwdMsg").text("请输入6位以上的密码!");
     			return;
     		}else{
     			$("#uPwdMsg").show();
     			$("#pwdMsg").hide();
     		}
     	}
     	
     	//手机号码
     	function valPhone(){
     		//<input type="text" name="userPhone" onblur="valPhone();"/>
			//<span id="uPhoneMsg">请输入11位手机号码</span>
			//<span id="phoneMsg" class="spanMsg"></span>
     		var phoneValue = $("input[name='userPhone']").val();
     		var phoneReg = /^\d{11}$/;
     		
     		if ($.trim(phoneValue) == '') {
     			$("#uPhoneMsg").hide();
     			$("#phoneMsg").text("请输入手机号码!");
     			return;
     		}else{
     			$("#uPhoneMsg").show();
     			//$("#phoneMsg").hide();
     		}
     		
     		if ($.trim(phoneValue) != '') {
				if(!phoneReg.test(phoneValue)){
					$("#phoneMsg").show();
					$("#phoneMsg").text("请输入11位手机号码!");
					$("#uPhoneMsg").hide();	
					return;
				}else{
					$("#uPhoneMsg").show();
					$("#phoneMsg").hide();
				}
     		}
     		
     	}
     	
     	//<input type="text" name="userEmail" onblur="valUserEmail();"/>
		//<span id="uEmail">请输入格式正确邮箱</span>
		//<span id="email" class="spanMsg"></span>
     	function valUserEmail(){
     		var userEmail = $("input[name='userEmail']").val();
     		var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/;
     		
     		if($.trim(userEmail) == ''){
     			$("#uEmail").hide();
     			$("#email").text("请输入你的邮件!");
     			return;
     		}else{
     			$("#uEmail").show();
			    //$("#email").hide();
     		}
     		
     		if($.trim(userEmail) != ''){
	    		if(!reg.test($.trim(userEmail))){
			          $("#uEmail").hide();
			          $("#email").text("请输入正确的邮件格式");
			          return false;
				}else{
					  $("#uEmail").show();
				      $("#email").hide();
				}
    		}
     	}
     	
     	function emptyUserInfo() {
     		$("#uNameMsg").text("");
     		$("#uPwdMsg").text("");
     		$("#rNameMsg").text("");
     		$("#uPhoneMsg").text("");
     		$("#uMobileMsg").text("");
     	}

</script>
